﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 任务8计数矩形的个数
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {


            Rectangle rectangle;        //声明矩形对象
            if (radioButton1.Checked)   //若“圆”单选按钮被选中，则创建圆对象
            {
                if (textBox1.Text == "")    //文本框内不输入参数，就调用默认构造函数
                {
                    rectangle = new Rectangle();
                }
                else
                {
                    double l = double.Parse(textBox1.Text);
                    rectangle = new Rectangle(l);
                }
                label3.Text = "对象创建成功！\n" + "圆的半径为：" + rectangle.Length
                    + "\n圆的面积为：" + rectangle.Area() + "\n圆对象的个数为："
           + Rectangle.GetSqrNum();
            }
            else           //若“椭圆”单选按钮被选中，则创建椭圆
            {
                if (textBox1.Text == "" && textBox2.Text == "")  //文本框内不输入参数，就调用默认构造函数
                {
                    rectangle = new Rectangle();
                }
                else
                {
                    double l = double.Parse(textBox1.Text);
                    double w = double.Parse(textBox2.Text);
                    rectangle = new Rectangle(l, w);
                }
                label3.Text = "对象创建成功！\n" + "椭圆长半轴为：" + rectangle.Length + "\n椭圆短半轴为：" + rectangle.Width
           + "\n椭圆的面积为：" + rectangle.Area() + "\n椭圆对象的个数为："
           + Rectangle.GetRectNum(); //使用类名调用静态方法，获取椭圆形对象个数
                
            }
           



        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
            {
                textBox2.Visible = false;
                label2.Visible = false;
                label1.Text = "半径：";

            }



        }
        class Rectangle
        {
            private double length;
            private double width;
            private static int rectNum;     //静态字段，用于统计椭圆对象个数
            private static int sqrNum;      //静态字段，用于统计圆对象个数  

            public static int GetRectNum()
            {
                return rectNum;
            }
            public static int GetSqrNum()
            {
                return sqrNum;
            }


            public Rectangle(double l, double w)     //声明构造函数
            {
                length = l;
                width = w;
                rectNum++;  //每创建一个椭圆对象，该静态变量增1
             
            }
            public double Length
            {
                get { return length; }
                set { length = value; }
            }
            public double Width
            {
                get { return width; }
                set { width = value; }
            }
            public double Area()
            {
                return length * width*3.14;
            }
            public Rectangle(double l)              //声明1个参数的圆构造函数重载
            {
                length = width = l;
                sqrNum++;   //每创建一个圆对象，该静态变量增1
            }
            public Rectangle()              //声明一个用默认构造函数，默认边长都为5，该函数调用其他构造函数
                : this(5, 5)
            {
            }


        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton2.Checked)
            {
                textBox2.Visible = true;
                label2.Visible = true;
                label1.Text = "半长轴";
            }

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

       

    }
}
